const Service = require('egg').Service;

class treeServerService extends Service {
  async index(subjectId) {
    const { config, ctx } = this;
    const { api } = config;
    const { chapterTree } =  api;
    let result = {
      data: {}
    };

    result = await ctx.curl(`${config.baseUrl}${chapterTree}?subjectId=${subjectId}`, {
      dataType: 'json'
    });
    return result.data;
  }
  
  async knowledgeTree(subjectId, gradePhase) {
    const { config, ctx } = this;
    const { api } = config;
    const { knowledgeTree } =  api;
    let result = {
      data: {}
    };

    result = await ctx.curl(`${config.baseUrl}${knowledgeTree}?subjectId=${subjectId}&gradePhase=${gradePhase}`, {
      dataType: 'json'
    });
    return result.data;
  }
}

module.exports = treeServerService;
